package com.jinlei.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinlei.dao.AdminDao;
import com.jinlei.entity.Admin;
import com.jinlei.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
// 事务标记   springboot里面只能使用注解配置事务  不能使用其他的
@Transactional(rollbackFor = Exception.class)
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDao adminDao;

    @Override
    public List<Admin> adminList() {
        return adminDao.select();
    }

    @Override
    public Map<String, Object> page(Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        PageInfo<Admin> pageInfo = new PageInfo<>(adminDao.select());
        Map<String, Object> map = new HashMap<>();
        map.put("list", pageInfo.getList());
        map.put("total", pageInfo.getTotal());
        map.put("pages", pageInfo.getPages());
        return map;
    }
}
